﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AutoplanetaTaskManager.Daos;
using AutoplanetaTaskManager.Daos.EntityFramework;

namespace AutoplanetaTaskManager.Views.Admin
{
    public partial class EmployeesManageForm : Form
    {
        private IUserDao _userDao = new UserDao();

        public EmployeesManageForm()
        {
            InitializeComponent();
        }

        private void EmployeesManageForm_Load(object sender, EventArgs e)
        {
            mainDataGridView.DataSource = _userDao.LoadEmployees();
        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            Dispose();
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            new AddEmployeeForm().ShowDialog();
            mainDataGridView.DataSource = _userDao.LoadEmployees();
        }

        private void editButton_Click(object sender, EventArgs e)
        {
            if (mainDataGridView.SelectedRows != null && mainDataGridView.SelectedRows.Count > 0)
            {
                int id = (int) mainDataGridView.SelectedRows[0].Cells[0].Value;
                new EditEmployeeForm(id).ShowDialog();
                mainDataGridView.DataSource = _userDao.LoadEmployees();
            }
        }

        private void removeButton_Click(object sender, EventArgs e)
        {
            if (mainDataGridView.SelectedRows != null)
            {
                int id = (int)mainDataGridView.SelectedRows[0].Cells[0].Value;
                new RemoveEmployeeForm(id).ShowDialog();
                mainDataGridView.DataSource = _userDao.LoadEmployees();
            }
        }
    }
}
